pub struct Solution;

impl Solution {
    pub fn license_key_formatting(s: String, k: i32) -> String {
        s.split("-")
            .map(|v| v.to_uppercase())
            .flat_map(|v| v.chars().collect::<Vec<char>>())
            .collect::<Vec<char>>()
            .rchunks(k as usize)
            .rev()
            .map(|v| v.iter().collect::<String>())
            .collect::<Vec<String>>()
            .join("-")
    }
}